package com.hsy.dormmanage.config;

import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger2配置信息
 * http://localhost:8080/swagger-ui.html
 */
@Configuration
@EnableSwagger2
public class Swagger2Config {


/*    @Bean
    public Docket createRestApi(){
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any()).build();
    }*/

    @Bean
    public Docket dormApiConfig(){

        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("adminApi")
                .apiInfo(dormApiInfo())
                .select()
                //只显示admin路径下的页面
                .paths(Predicates.and(PathSelectors.regex("/dorm/.*")))
                .build();

    }
/*    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("DormManage API Doc")
                .description("宿舍管理系统的Api文档.")
                .version("1.0")
                .build();
    }*/
    private ApiInfo dormApiInfo(){

        return new ApiInfoBuilder()
                .title("宿舍管理系统的Api文档.")
                .description("本文档描述了宿舍管理系统的接口定义")
                .version("1.0")
                .contact(new Contact("hsy", "hsy.com", "2581098813@qq.com"))
                .build();
    }

}
